package com.tokenmaster.aitrade.init.history_okex;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.log4j.Logger;

import com.tokenmaster.aitrade.common.system.IndexConfig;
import com.tokenmaster.aitrade.common.system.KLinePoint;
import com.tokenmaster.aitrade.data.SystemDB;
import com.tokenmaster.aitrade.market.okex.IOkex_Parameter.Contract_types_Enum;
import com.tokenmaster.aitrade.market.okex.IOkex_Parameter.Types_Enum;
import com.tokenmaster.aitrade.market.okex.Market_Okex_Future;
import com.tokenmaster.aitrade.market.okex.Market_Okex_Spot;

/**
 * @Description: 初始化 okex 历史数据
 * @author buxinyun
 * @date 2018年7月24日
 *
 */
public class HistoryData_Okex {

	public static void main(String[] args) {

		Logger logger = Logger.getLogger(HistoryData_Okex.class);

		Market_Okex_Future market_Okex_Future = Market_Okex_Future.getInstance();
		Market_Okex_Spot market_Okex_Spot = Market_Okex_Spot.getInstance();

		SimpleDateFormat sformat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");

		try {
			// 从OK获取K线
			IndexConfig indexConfig = new IndexConfig();
			indexConfig.setSymbol("btc_usdt");
			indexConfig.setTypes_Enum(Types_Enum.MIN15);
			indexConfig.setContract_type(Contract_types_Enum.THIS_WEEK);

			List<KLinePoint> kLinePoints = market_Okex_Spot.getKLines(indexConfig);

			for (KLinePoint kPoint : kLinePoints) {
				double lastUnixTime = kPoint.getUnixTime();
				String timestr = sformat.format(lastUnixTime);

				if (SystemDB.getInstance().getKLinePoint("btc_usdt", "15min", kPoint.getUnixTime()) == null){
					SystemDB.getInstance().insertKLine(kPoint);
				}

				

				logger.info(timestr);
			}

			// 保存进入数据库

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
